package vikings.aps;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataValidation {
	
	public DataValidation (){}
	
	public static boolean isEmailValid(String email){   
		boolean isValid = false;   
		
		/*  
		11.Email format: A valid email address will have following format:  
		12.        [\\w\\.-]+: Begins with word characters, (may include periods and hypens).  
		13.    @: It must have a '@' symbol after initial characters.  
		14.    ([\\w\\-]+\\.)+: '@' must follow by more alphanumeric characters (may include hypens.).  
		15.This part must also have a "." to separate domain and subdomain names.  
		16.    [A-Z]{2,4}$</STRONG> : Must end with two to four alaphabets.  
		17.(This will allow domain names with 2, 3 and 4 characters e.g pa, com, net, wxyz)  
		18. 
		19.Examples: Following email addresses will pass validation  
		20.abc@xyz.net; ab.c@tx.gov  
		21.*/  
		
		//Initialize reg ex for email.   
		String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";   
		CharSequence inputStr = email;   
		//Make the comparison case-insensitive.   
		Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);   
		Matcher matcher = pattern.matcher(inputStr);   
		if(matcher.matches()){   
		isValid = true;   
		}   
		return isValid;   
		} 
	
	public static boolean isPhoneNumberValid(String phoneNumber){   
		boolean isValid = false;   
		/* Phone Number formats: (nnn)nnn-nnnn; nnnnnnnnnn; nnn-nnn-nnnn  
		    ^\\(?</STRONG> : May start with an option "(" .  
		    (\\d{3})</STRONG>: Followed by 3 digits.  
		    \\)?</STRONG> : May have an optional ")"  
		    [- ]?</STRONG> : May have an optional "-" after the first 3 digits or after optional ) character.  
		    (\\d{3})</STRONG> : Followed by 3 digits.  
		     [- ]? </STRONG>: May have another optional "-" after numeric digits.  
		     (\\d{4})$</STRONG> : ends with four digits.  
		 
		         Examples: Matches following <A href="http://mylife.com">phone numbers</A>:  
		         (123)456-7890, 123-456-7890, 1234567890, (123)-456-7890  
		 
		*/  
		//Initialize reg ex for phone number. </CODECOMMENTS>   
		String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";   
		CharSequence inputStr = phoneNumber;   
		Pattern pattern = Pattern.compile(expression);   
		Matcher matcher = pattern.matcher(inputStr);   
		if(matcher.matches()){   
			isValid = true;   
		}   
			return isValid;   
	}

}
